<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>付款记录修改</title>
<% request.setAttribute("menu", 1); %>
<%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
<link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css"/>
<link rel="stylesheet" href="<%=basePath%>css/system.css" media="all"/>
<link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />
<link rel="stylesheet" href="<%=basePath%>css/YE.css" media="all" />

<style type="text/css">
	.layui-form-label i {color: red; padding-right: 3px;}
	.YE-history-times{float:right;}
	.bianji{width:30px;height:30px;background:url(../images/sprite.png);background-position:-170px -174px;}
</style>

</head>
<body>

<!-- 付款记录 -->
<div id="TM-layui-pay" >
	<div class="TM-he-tong admin-entering">
		<form class="layui-form TM-entering-form" action="" id="enterform" novalidate="novalidate">
        	<div class="layui-form-item TM-hetong-zhengshu">
				<c:forEach items="${record}" var="itemObj">
             		  <div class="layui-input-block layui-ye-block">
		                <div class="YE-hetong-block" style="float:left;">
		                    <ul class="clefix YE-history-text">
		                        <li class='${itemObj.approvalstatus==2?"YE-history-bg":"YE-history-bgone"}'><span></span></li>
		                    </ul>
		                    <ul class="clefix YE-history-text">
		                    	<li>审批状态:<span>
	              	  				<c:if test="${itemObj.approvalstatus == 0}">审批中</c:if>
		                			<c:if test="${itemObj.approvalstatus == 1}">待审批</c:if>
		                			<c:if test="${itemObj.approvalstatus == 2}">审批通过</c:if>
		                			<c:if test="${itemObj.approvalstatus == 3}">审批驳回</c:if>
	              	  			</span></li>
		                        <li>申请人：<span>${itemObj.createuserName}</span></li>
		                        <li>证书用途：<span>${itemObj.usetype==0?"挂资质":"挂项目"}</span></li>
		                        <li>转账类型：<span>${itemObj.transfertype==0?"现金":"转账"}</span></li>
		                        <li>户名：<span>${itemObj.name}</span> </li>
		                        <li>账号：<span>${itemObj.cardnumber}</span></li>
		                        <li>备注：<span>${itemObj.remark}</span></li>
		                    </ul>
		                    <ul class="clefix YE-history-textone">
		                        <li>付款金额：<span>${itemObj.totalamount}</span></li>
		                        <li>付款类型：<span>${itemObj.paytype==0?"预付款":"全款"}</span></li>
		                        <li>来源：<span>${itemObj.source==0?"个人":"中介"}</span></li> <br>
		                        <li>开户银行：<span>${itemObj.bankname}</span></li>  
		                                
		                    </ul>
		                    <ul class="clefix YE-history-texttwo">
		                        <li><%-- 签约年限：<span><dic:cf type="1" name="life_type" value="${info.lifetype}"/></span> --%></li><br>
		                        <li><span></span></li><br>
		                        <li><span></span></li></br>
		                        <li><span></span> </li><br>
		                    </ul>
		                    <ul class="clefix YE-history-times"><li class="bianji uppayinfo" appdata="${itemObj.approvalstatus}" iddata="${itemObj.id}" coniddata="${itemObj.contractid}"></li></ul>
		                    <ul class="clefix YE-history-time">	  
		                        <li>申请时间:${itemObj.createdate.substring(0,10)}</li>
		                    </ul>
		                </div>                
		            </div>
				</c:forEach> 
        	</div>     	       
    	</form>
	</div>
</div>

<!-- 付款修改弹窗开始 -->

<div id="TM-layui-diankuan" style="display:none;">
	<div class="TM-he-tong admin-entering">
		<form class="layui-form TM-entering-form" action="" id="diankuanform"   novalidate="novalidate">
	        <div class="form-left">
	            <div class="layui-form-item">
	                <label class="layui-form-label">申请人 : </label>
	                <div class="layui-input-block dkrname" ></div>
	                 <input type="hidden" name="cusid" id="rcid" >
	                  <input type="hidden" name="type" value="0" >
	                  <input type="hidden" name="contractid" id="contractid" value="">
	                  <input type="hidden" name="id" id="fkid" value="">
	            </div>
	            <!-- <div class="layui-form-item telitem" style="display:none;">
	               <label class="layui-form-label"><i>*</i><span>收款人电话 :</span> </label>
	               <div class="layui-input-inline" style="width:200px">
	        			<input type="text" name="tel" id="tel"    autocomplete="off" class="layui-input"  >
	        			<input type="hidden" name="isadditional" id="isadditional" value="0"   >
	        		</div>
	        		 <div class="layui-form-mid layui-word-aux">便于财务核查</div>
	            </div>   -->
	            <div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i><span>金额 : </span></label>
	                <div class="layui-input-inline" style="width:100px">
	        			<input type="text" name="totalamount" id="hktotalamount"  total="0" autocomplete="off" class="layui-input" >
	        		</div>
	        		<div class="layui-form-mid layui-word-aux">合同总金额(<span id="dkhtzje"></span>)</div>
	            </div>   
	            <div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i><span>户名 : </span></label>
	                <div class="layui-input-block">
	        			<input type="text" name="name" id="name"   autocomplete="off" class="layui-input" >
	        		</div>
	            </div> 
	            <div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i><span>卡号 : </span></label>
	                <div class="layui-input-block">
	        			<input type="text" name="cardnumber" id="cardnumber" onkeyup="formateBankNo(this)" onkeydown="formateBankNo(this)"  autocomplete="off" class="layui-input" >
	        		</div>
	            </div>                  
	        </div>
	        <div class="form-right">
	            <div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i><span>付款类型 : </span></label>
	                <div class="layui-input-block">
	        		  <select name="paytype" lay-filter="paytype" id="fkpaytype">
				        <option value="0" selected="selected">垫款</option>
				        <option value="1" selected="selected">全款</option>
				      </select>
	        		</div>
	            </div>
	            <div class="layui-form-item warehouse" style="display:;">
	               <label class="layui-form-label"><i>*</i><span>证书用途: </span></label>
	               <div class="layui-input-block utype">
				      <select name="usetype"  id="usetype" lay-filter="usetype">
				        <option value="">证书用途</option>
				        <option value="0">挂资质</option>
				        <option value="1">挂项目</option>
				      </select>
				    </div>
	            </div> 
	            <div class="layui-form-item">
	            	<label class="layui-form-label"><i>*</i><span>转账类型 : </span></label>
	                <div class="layui-input-block">
				      <select name="transfertype" id="fktransfertype" lay-filter="transfertype">
				      	<option value="1">转账</option>
				        <option value="0">现金</option>
				      </select>
				    </div>
	            </div>    
	             <div class="layui-form-item">
	            	<label class="layui-form-label"><i>*</i><span>来源 : </span></label>
	                <div class="layui-input-block">
				      <select name="source" lay-filter="source" id="fksource">
				           <option value="0">个人</option>
				        <option value="1">中介</option>      
				      </select>
				    </div>
	            </div>    
	            <div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i><span>开户行 : </span></label>
	                <div class="layui-input-block">
	        			<input type="text" name="bankname" id="kw" autocomplete="off" class="layui-input" placeholder="请输入银行名称">
	        			<div id="append"></div>
	        		</div>
	            </div> 
	        </div>
	     	<div class="layui-form-item TM-hetong-jilu">
	      		<label class="layui-form-label"><i>*</i>费用说明 : </label>
	            <div class="layui-input-block">
	      			<textarea placeholder="请输入内容" name="remark"  id="dkremark" class="layui-textarea"></textarea>
	    		</div>
	     	</div> 
	     	<div class="layui-form-item TM-hetong-jilu">
	      		<label class="layui-form-label"><i>*</i>修改说明 : </label>
	            <div class="layui-input-block">
	      			<textarea placeholder="请输入内容" name="modifyRecord"  id="dkmodifyRecord" class="layui-textarea"></textarea>
	    		</div>
	     	</div> 
    	</form>
	</div>
</div>

<!-- 付款修改弹窗结束 -->

<script type="text/javascript">
	
layui.use(['laytpl','form','laydate','laypage','form'], function() {
	var $ = layui.jquery,
    	layer = layui.layer,
    	laytpl = layui.laytpl,
    	laypage = layui.laypage;
	var form = layui.form();
	var tjstate =0;
	
	//点击修改付款记录
	$(document).on("click",".uppayinfo",function(){
		
		var appdata = $(this).attr("appdata");
		var id = $(this).attr("iddata");
		
		//待审批和审批通过的可以被修改
		if (appdata == 2){
			$.ajax({
				type : "post",
				url : "/customer/ajaxgetpaymoney",
				data : {id : id},
	    		dataType : "json",
	    		async : false,
	    		success : function(data){
	    			
	    			//要展示的内容
	    			var createusername = data.createuserName; //申请人
	    			var cusid = data.cusid; //客户id
	    			var contractid = data.contractid; //合同id
	    			var id = data.id;
	    			var totalamount = data.totalamount; //金额
	    			
	    			var name = data.name; //户名
	    			var cardnumber = data.cardnumber; //卡号
	    			var paytype = data.paytype; //付款类型
	    			var usetype = data.usetype; //证书用途
	    			var transfertype = data.transfertype; //转帐类型
	    			var source = data.source; //来源
	    			var bankname = data.bankname; //开户行
	    			var remark = data.remark;
	    			
	    			$("#fkid").val(id);
	    			$(".dkrname").text(createusername);
	    			$("#rcid").val(cusid);
	    			$("#contractid").val(contractid);
	    			$("#hktotalamount").val(totalamount);
	    			$("#name").val(name);
	    			$("#cardnumber").val(cardnumber);
	    			$("#fkpaytype").val(paytype);
	    			$("#usetype").val(usetype);
	    			$("#fktransfertype").val(transfertype);
	    			$("#fksource").val(source);
	    			$("#kw").val(bankname);
	    			$("#dkremark").text(remark);
	    			form.render();
	    			
					//判断是否有正在修改的内容
					var type = 2
					
					$.ajax({
						type : "post",
        				data : {id : id,type : type},
        				url : "/customer/checkhistoryisexist",
        	    		dataType : "json",
        	    		async : false,
        	    		success : function(data){
        	    			if (data > 0) {
        	    				layer.msg("有未审批的修改记录,请等待审批完成后,再次申请",{icon: 2});
        	    			} else {
        	    				layer.open({
        			                title:'付款信息修改',
        			                type:1, 
        			                content:$('#TM-layui-diankuan'),
        			                btn: ['修改', '取消'],
        			                shadeClose:true,
        			                btnAlign:'c',
        			                area:['99%','99%'],
        			                yes: function(){ 
        			                	 if(tjstate ==0){
        			                		 $("#diankuanform").submit();
        			                	 }else{
        			                		 layer.msg("信息提交中,请勿重复提交",{icon: 0});
        			                	 }
        			                },
        			      			success: function(layero, index){
        			      				tjstate =0;
        			      			}
        			        	});
        	    			}
        	    		}
					});
	    		}
			});
		} else {
			layer.msg('只能修改已通过审批或待审批的付款记录', {icon: 2});
		}
    });
	
	
	//付款表单
	$("#diankuanform").validate({
		rules: {
			arrivaltime : {
      			required:false
      		},
      		tel:{
      			tel:true
      		},
      		totalamount : {
      			required:true,
      			digits:true
      			//,checkmoney:true
      		},
      		name : {
      			required:true
      		},
      		cardnumber : {
      			required:true
      		},
      		bankname : {
    			required:true
    		},
    		remark : {
    			required:true
    		},
    		modifyRecord : {
    			required:true
    		}
		},
		messages: {
			arrivaltime : {
      			required:"请选择回款时间"
      		},
      		tel:{
      			required:"请填写收款人电话，便于财务核查！" 
      		},
      		totalamount : {
      			required:"请填写垫款金额",
      			digits:"请填写正确金额"
      		},
      		name : {
      			required:"请填写姓名"
      		},
      		cardnumber : {
      			required:"请填写银行卡号"
      		},
      		bankname : {
    			required:"请填写开户行"
    		},
    		remark : {
    			required:"请填写费用说明"
    		},
    		modifyRecord : {
    			required:"请填写修改备注"
    		}
		},
		errorPlacement: function(error, element) {
			tjstate =0;
			layer.tips(error.text(), element, {
      			tips: [2,tipColor],
       		 tipsMore: true
       		});
		},
		submitHandler: function(formobj) {
			
			tjstate =1;
			var values = $("#diankuanform").serialize();
			$.ajax({
				type : "post",
				url : "/customer/upfkmoneylog",
				data : values,
				dataType : "json",
				async : false,
				success : function(data){
					if (data == 1) {
  						layer.closeAll();
  		 				layer.msg('付款修改申请成功等待审核', {icon: 1},function(){
  		 					window.location.reload();
  		 				});
  					} else {
  						tjstate= 0;
  						layer.msg("付款修改申请失败");
  					}
				}
			});
		}
	});
	
	
	
});
	
</script>

</body>
</html>